<template>
  <div class="container">
    <div v-if="skeletonLoading" class="skeleton-box">
      <div class="skeleton-animate"></div>
      <div :style="{
        marginTop: spaceToBarHeight ? spaceToBarHeight + 'px' : '105px',
      }"></div>
      <div class="skeleton-shop">
        <div class="skeleton-menu flex v-align-c pad-t-5 pad-b-5 mar-b-16">
          <div class="flex-item">
            <div class="skeleton-layer layer-2 flex">
              <span v-for="(item, index) in 4" :key="index" class="flex-item mar-r-26 animate-blink bg-box"></span>
            </div>
          </div>
          <div class="width-50 flex v-align-c">
            <div class="flex-item"></div>
            <img v-if="fileSpace" class="width-36 height-36" :class="subMore ? 'rotate' : ''" :src="fileSpace + '/images/icon-sub-down-2.png'" alt="">
          </div>
        </div>
        <div class="skeleton-layer layer-1 animate-blink bg-box"></div>
        <div v-for="(item, index) in 5" :key="index" class="skeleton-layer layer-4 flex">
          <div class="width-80 height-80 mar-r-7 animate-blink bg-box"></div>
          <div class="flex-item">
            <span class="animate-blink bg-box height-21"></span>
            <span class="bar-s animate-blink bg-box width-84 height-21 mar-t-8"></span>
            <span class="bar-s animate-blink bg-box width-60 height-21 mar-t-9"></span>
          </div>
        </div>
      </div>
    </div>
    <template v-if="!getCustomerId">
      <get-user-info v-if="isGetUserInfo" :showBackBtn="showBackBtn" @showPage="showPage" @authPhoneInfo="authPhoneInfo"></get-user-info>
      <get-phone-info v-if="isGetPhoneInfo" :showBackBtn="showBackBtn" @showPage="showPage"></get-phone-info>
    </template>
    <template v-if="getCustomerId && !getPhone">
      <get-phone-info v-if="isGetPhoneInfo" :showBackBtn="showBackBtn" @showPage="showPage"></get-phone-info>
    </template>
    <!-- 搜索样式展示 -->
    <div class="search-bar flex v-align-c" :style="{top: statusBarTop+'px'}">
      <div class="font-22 pad-l-6 pad-r-12">分类</div>
      <div class="search flex-item" @click="goSearch">
        <van-icon name="search" color="#aeaeae" size="16px" class="mar-l-8 mar-r-4 flex" />
        <div class="font-14">搜索</div>
      </div>
      <div class="width-100"></div>
    </div>
    <!-- 分类模板2开始 -->
    <template v-if="subTab.length !== 0">
      <div v-if="tempData.templateType === 2" class="sub-tab bg-color-white" :style="{top:spaceToBarHeight +otherHeight + 8 +'px'}" :class="iosType ? 'height-51' : 'height-52'">
        <van-tabs :active="activeSub" @change="tabClick" :color="getAppInfo.style.color2" :border="false">
          <div v-for="(item, index) in subTab" :key="index">
            <van-tab :title="item.categoryName"></van-tab>
          </div>
        </van-tabs>
        <div v-if="fileSpace" class="tab-more flex flex-center" :class="iosType ? '' : 'tab-more-and'" @click="tabLayerShow">
          <img v-if="fileSpace" class="width-36 height-36" :class="subMore ? 'rotate' : ''" :src="fileSpace + '/images/icon-sub-down-2.png'" alt="">
        </div>
      </div>
      <div v-if="subMore" class="sub-tab-layer">
        <ul :style="{top: 8+spaceToBarHeight + otherHeight+48 +'px', paddingTop: bScreeSpace + 7 +'px'}">
          <li class="font-12"
            :style="{color:activeSub === index ? getAppInfo.style.color2 :'', background:activeSub === index ? '#fff' :'',borderColor:activeSub === index ? getAppInfo.style.color2 :'',}"
            @click="subTabLayer(index, item)" v-for="(item, index) in subTab" :key="index">{{ item.categoryName }}</li>
          <!-- <li class="font-12" :class="activeSub === index ? 'actived' : ''" @click="subTabLayer(index, item)" v-for="(item, index) in subTab" :key="index">{{ item.categoryName }}</li> -->
        </ul>
        <div class="sub-layer-bg" :style="{top: leftHight + bScreeSpace + 102 +'px'}" @click="subMore = false"></div>
      </div>
    </template>
    <!-- 分类模板2结束 -->
    <div class="main" v-if="categoryNull === false">
      <scroll-view
        class="left-bar"
        :scroll-into-view="'category-' + currentCategory.categoryId"
        :scroll-y="true"
        :style="{top:spaceToBarHeight+otherHeight+ 8 + 'px',height: 'calc(100vh - ' + (8+otherHeight +spaceToBarHeight) + 'px)'}">
        <div
          class="item-bar"
          :id="leftMenuClick ? '' : 'category-' + item.categoryId"
          :class="{'item-bar--active': activeIndex === index}"
          v-for="(item, index) in listCategory"
          :key="index"
          @click="activeClick(index, item)">
          {{item.categoryName}}<div :class="{'leftline': activeIndex === index}" :style="{'background':getAppInfo.style.color2}"></div>
        </div>
      </scroll-view>
      <scroll-view class="right-bar" @scrolltolower="scrollLower" :scroll-y="true" :style="{top:spaceToBarHeight +otherHeight+ 8 + 'px',height: 'calc(100vh - ' + (8+otherHeight +spaceToBarHeight) + 'px)'}">
        <div v-if="tempData.templateType === 2" class="height-51"></div>
        <div class="pad-t-10" :class="(!currentCategory.posterUrl && tempData.templateType === 1) ? 'mar-t-5' : ''">
          <div class="pad-r-11 pos-rel" v-if="currentCategory.posterUrl" :class="(tempData.templateType === 3 || tempData.templateType === 4) ? 'mar-b-10' : ''">
            <button v-if="currentCategory.linkType === '1002'" :send-message-title="memberInfo.nickname + '的V客主页'" plain send-message-img="https://veekrayimg.joinsun.vip/images/share-s-picture.png"
              show-message-card="true" send-message-path="/pages/home/main" open-type="contact" class="contactBtn hidden-submit button-icon"></button>
            <img class="img-top-scr mar-b-10" :src="currentCategory.posterUrl" mode="widthFix" @click="linkTo" />
          </div>
        </div>
        <template v-if="tempData.templateType === 1 || tempData.templateType === 2">
          <div class="shop-bar flex mar-b-10" v-for="(item, index) in listData" :key="index" @click="pageTo(item)">
            <div class="img-item-box pos-rel">
              <!-- 跨境图标 -->
              <div class="cross-border-pic">
                <!-- 跨境保税 -->
                <img
                  v-if="fileSpace && item.crossBorderType === 2 && item.crossBorderLabelType === 1"
                  :src="fileSpace + '/images/icon-cross-border-s.png'"
                  class="icon-cross-border cross-s"
                  alt="">
                <!-- 海外直邮 -->
                <img
                  v-if="fileSpace && item.crossBorderType === 2 && item.crossBorderLabelType === 2"
                  :src="fileSpace + '/images/icon-cross-border-s-22.png'"
                  class="icon-cross-border cross-s"
                  alt="">
              </div>
              <div v-if="item.stock === 0 || item.goodsStatus === 0" class="sell-out">
                <div class="del-layer align-c">
                  <div class="font-14">已售完</div>
                  <div class="font-9 mar-t--2">SOLD OUT</div>
                </div>
              </div>
              <img
                v-if="currentCategory.categoryType===1"
                :src="item.firstImage + '?imageView2/1/w/300/h/300'"
                mode="aspectFill"
                class="img-item" />
              <img
                v-if="currentCategory.categoryType===2 || currentCategory.categoryType===3"
                :src="item.mainImage + '?imageView2/1/w/300/h/300'"
                mode="aspectFill"
                class="img-item" />
              <div
                v-if="item.totalLimitNum"
                class="limit-buy-bar">限购{{ item.totalLimitNum }}件</div>
            </div>
            <div class="content-item-box mar-l-8 flex-item pad-t-3 pad-r-15">
              <div class="flex content-title font-w line-2 mar-t--2">
                <span v-if="item.activityTypeLabel" class="tag-goods">
                  <span>{{ item.activityTypeLabel }}</span>
                </span>{{item.title}}
              </div>
              <div class="height-17 mar-t-4 mar-b--4">
                <div v-if="item.shareShow && getCustomerId" class="self-buy">
                  <div class="self-buy-left">{{getAppInfo.commissionAlias || '分销赚'}}</div>
                  <div class="self-buy-right"><span style="color:#ffe200;">{{item.income}}</span>元</div>
                </div>
              </div>
              <div class="content-foot mar-t-25 pad-t-7 pad-b-12">                
                <div class="price-row flex flex-between mar-t--5">
                  <div class="price-box mar-t--12">
                    <div
                      v-if="currentCategory.categoryType === 1"
                      class='price cate-price font-16 font-w min-short-w'>
                      <span class="font-11">¥</span>{{ item.price }}
                    </div>
                    <template v-if="currentCategory.categoryType === 2 || currentCategory.categoryType === 3">
                      <div>
                        <span
                          class='price cate-price font-16 font-w min-short-w'>
                          <span class="font-11">¥</span>{{ item.bestPrice }}
                        </span>
                      </div>
                      <div
                        class="price over-price font-11 height-11">
                        <template v-if="item.scribingPrice">¥{{ item.scribingPrice }}</template>
                      </div>
                    </template>
                    <!-- 商品设置会员价处理；有会员价展示权限高于普通正常价格 -->
                  </div>
                  <div class="font-12 height-33">
                    <template v-if="tempData.quickBuy && item.stock">
                      <div
                        v-if="!item.selShow"
                        @click.stop.prevent="showCart(item)"
                        :style="{color:getAppInfo.style.color5, background:getAppInfo.style.color2}"
                        class="in-cart-btn font-11">加入购物车</div>
                      <div v-else class="height-33 mar-t--3 mar-r--10" :class="iosType ? 'mar-t--3' : 'mar-t--4'">
                        <van-stepper
                          v-model="item.goodsNum"
                          :class="'step-' + getAppInfo.style.styleType"
                          class="goods-step"
                          :min="item.skuFlag ? item.goodsNum : 0"
                          disable-input
                          :max="item.groupLimitNum"
                          @click.stop.prevent=""
                          @minus="onMinusGoodsNum($event, item)"
                          @plus="onPlusGoodsNum($event, item)"
                          @change="onChangeGoodsNum($event, item)" />
                      </div>
                    </template>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
        <!-- 分类模板3、4开始 -->
        <template v-else>
          <div class="temp-subcat-list" :class="tempData.templateType === 4 ? 'pad-b-11' : ''" v-for="(secItem, secIndex) in subTab" :key="secIndex">
            <h2 v-if="tempData.templateType === 4" class="pad-b-11">{{secItem.categoryName}}</h2>
            <ul>
              <template v-for="(thrItem, thrIndex) in secItem.children">
                <li :key="thrIndex" @click="goShopAllPage(thrItem)">
                  <img v-if="thrItem.categoryImage" mode="aspectFill" class="width-80 height-80" :src="thrItem.categoryImage + '?imageView2/1/w/160/h/160'" />
                  <img v-if="!thrItem.categoryImage && fileSpace" :src="fileSpace + '/images/default-category.png'" class="width-80 height-80" alt="">
                  <div class="font-13 pad-t-6 pad-b-6">{{thrItem.categoryName}}</div>
                </li>
                <li v-if="(thrIndex + 1) % 3 == 0" class="clear-li" :key="thrIndex"></li>
              </template>
            </ul>
          </div>
        </template>
        <!-- 分类模板3、4结束 -->
        <!-- 暂无数据 -->
        <div class="nodata" v-if="shopSortNull">
          <img v-if="fileSpace" :src="fileSpace + '/images/shop-nodata.png'" class="width-274 height-65" alt="">
          <div class="align-c mar-t-20 font-16 font-color-6">
            暂无数据~
          </div>
        </div>
        <div v-if="finishedLine" class="base-line-shop pad-t-15 pad-b-15">
          <base-line title='我是有底线滴'></base-line>
        </div>
      </scroll-view>
    </div>
    <!-- 暂无数据 -->
    <div class="category-nodata" :class="getVeekrayStatus !== 1 ? 'category-nosetting' : ''" v-if="categoryNull">
      <img v-if="fileSpace" :src="fileSpace + '/images/shop-nodata.png'" class="width-375 height-91" alt="">
      <div class="align-c mar-t-5 font-16 font-color-6">
        暂无数据~
      </div>
      <div class="goSetting" v-if="checkOwner && getVeekrayStatus === 1">
        <button @click="$pt.navigateTo({url: '/pages/shop/editView/main'})">前往设置</button>
      </div>
    </div>
    <div class="fix-r-btn flex-col">
      <!-- 回我店铺 -->
      <div class="align-r pad-r-13">
        <back-btn urlFrom="shop" />
      </div>
    </div>
    <!-- <back-btn urlFrom="shop" /> -->
    <!--sku选择-->
    <get-sku-buy v-if="getAppInfo.style" ref="getSkuBuy"
      :styleColor="getAppInfo.style" :goodsType="goodsType"
      :room_id="room_id" :goodsData="goods" :skuPropList="skuPropList"
      :skuList="skuList" :values="values" :featuresType ="featuresType"
      @finished="getSkuBuyFinished" @close="getSkuBuyClose">
    </get-sku-buy>
  </div>
</template>

<script>
import GetUserInfo from '@/components/GetUserInfo'
import GetPhoneInfo from '@/components/GetPhoneInfo'
import SettingBtn from '@/components/SettingBtn'
import CartBadge from './components/CartBadge'
import BackBtn from '@/components/BackBtn'
import GetSkuBuy from '@/components/GetSkuBuy'
import headerNav from '@/components/headerNav'

import {
  getShopCartVeekray,
  pageUserGoodsByMemberId,
  getCategoryNum,
  addShoppingCart,
  getProjectGoodsSku,
  categoryTemplate,
  listNextCategoryByParentId
} from '@/api/shop'
import { listOneGoodsCategory } from '@/api/distribution'
import { getMemberInfo } from '@/api/home'
import { getOpenVipOnlineFlag, getAppInfo, getAuthority } from '@/api/common'
import { setStoreCardFlag, setMemberNature, setShowBuyCard, setCategoryInfo, setCartBadge } from '@/utils/auth'
import baseLine from '@/components/BaseLine/index'
import { getAuth } from '@/api/login'
import { appColor } from '@/api/appColor'
export default {
  components: {
    GetUserInfo,
    GetPhoneInfo,
    SettingBtn,
    CartBadge,
    baseLine,
    BackBtn,
    GetSkuBuy,
    headerNav
  },
  data() {
    return {
      effectiveList: [],
      feeGoodsList: [],
      groupBuyGoodsList: [],
      promotionList: [],
      listQueryCart: {
        memberId: '',
        customerId: '',
        enterpriseId: ''
      }, // 获取购物车列表信息 参数集合
      spaceBarHeight: 0,
      activeIndex: 0,
      listCategory: [],
      listData: [],
      spaceHight: 0, // 头部高度
      seachHeight: 0, // 搜索框高度
      leftHight: 0, // 类目栏top
      listQuery: {
        categoryId: '',
        categoryType: '',
        memberId: '',
        customerId: '',
        upperShelfFlag: 1,
        currentPage: 1,
        size: 10
      },
      pullLoad: {
        loading: false,
        finished: false
      },
      finishedEls: false,
      shopSortNull: false,
      categoryNull: false,
      listBanner: [],
      isPreview: true,
      hasCategory: false,
      currentCategory: {
        categoryId: null,
        categoryType: 1,
        enterpriseCategoryId: null,
        posterUrl: null,
        linkParams: null,
        linkType: null
      },
      categoryData: [],
      isInitDone: false,
      readShopGuideEdit: true,
      isGetUserInfo: false,
      isGetPhoneInfo: false,
      topBoolean: true,
      memberInfo: {},
      customerInfo: {},
      timerShow: null,
      timerHide: null,
      categoryNum: 0,
      current: 0,
      openVip: '1',
      pageLoad: true,
      finishedLine: false,
      categoryId: '',
      leftMenuClick: false,
      cartBadge: 1,
      tempData: {
        quickBuy: 1,
        templateType: 1
      },
      currentTemp: null,
      activeSub: 0,
      subTab: [],
      subMore: false,
      iosType: false,
      goodsType: '',
      room_id: null,
      goods: {},
      skuPropList: [],
      skuList: [],
      values: [],
      linkList: {
        1001: '/pages/personal/coupon/coupon-center/main', // 领券中心
        1002: '/pages/contact-btn/main', // 微信客服
        1004: '/pages/shop/main', // 分类链接
        1005: '/pages/home/main', // 首页
        1006: '/pages/shop/main', // 分类
        1007: '/pages/shop/cart/main', // 购物车
        1008: '/pages/personal/main', // 个人中心
        1009: '/pages/home/content-center/main', // 内容中心
        1010: '/pages/shop/searchView/main', // 搜索页面
        1101: '/pages/home/second-custom/main', // 自定义页面
        1401: '/pages/home/live-list/main', // 直播列表
        1501: '/pages/home/default-seckill/main', // 限时秒杀
        1502: '/pages/home/default-seckill/main', // 社区团购
        2001: '/pages/shop/detail/main', // 商品详情
        4001: '/pages/home/content-center/content-detail/main' // 内容中心详情
      },
      menuHeight: 0,
      bScreeSpace: 0,
      fastGoods: [],
      memberEnterpriseId: '',
      goodsLoad: 0,
      getAppInfo: {},
      showBackBtn: true,
      statusBarHeight: 0,
      barHeight: 0,
      spaceToBarHeight: 0,
      statusBarTop: 0,
      otherHeight: 0,
      navList: [],
      shopSelectionAuthority: 0, // 小B选品增值功能
      skeletonLoading: true,
      headerNavH: 0,
      featuresType: ''
    }
  },
  onLoad() {
    // 初始化data
    Object.assign(this.$data, this.$options.data())
    this.getAppInfo = this.$pt.getStorageSync('appInfo')
    if (this.globalData.firstBuyCard) {
      this.readShopGuideEdit = this.$pt.getStorageSync('readShopGuideEdit')
    }
    this.customerInfo.avatar = 'https://veekrayimg.joinsun.vip/head-portrait.png'
    this.getAuth()
    this.skeletonLoading = true
  },
  onPullDownRefresh() {
    this.$utils.showToast({
      title: '加载中',
      icon: 'loading'
    })
    this.finishedEls = false
    this.$pt.showTabBar({animation: false})
    // 页面初始请求事件
    this.initDataEls()
    setTimeout(() => {
      this.$pt.stopPullDownRefresh()
    }, 500)
  },
  onShow() {
    this.finishedEls = false
    this.$pt.showTabBar({animation: false})
    this.spaceBarHeight = this.$pt.getSystemInfoSync()['statusBarHeight'] - 20
    this.getHeight(this.spaceBarHeight)
    this.getAppEls()
    // 设置购物车角标数
    if (this.$pt.getStorageSync('cartBadge')) {
      this.$pt.setTabBarBadge({
        index: 2,
        text: String(this.$pt.getStorageSync('cartBadge'))
      })
    } else {
      this.$pt.removeTabBarBadge({
        index: 2
      })
    }
    // 链接选择器分类跳转进入
    this.leftMenuClick = false
    if (this.$pt.getStorageSync('categoryInfo')) {
      // console.log('categoryInfo 11', this.$pt.getStorageSync('categoryInfo'))
      this.categoryId = ''
      this.leftMenuClick = false
      this.categoryId = this.$pt.getStorageSync('categoryInfo').categoryId
      this.initDataEls()
    } else {
      this.leftMenuClick = true
    }
    // 分类页面分享MemberId处理
    let queryMemberId = this.getCurrentPage().query.memberId
    if (queryMemberId) {
      this.$utils.setMyId(queryMemberId)
      this.$root.$mp.appOptions.query = {}
    }
    // 清除自定义二级页缓存ID
    if (this.$pt.getStorageSync('secondPage')) {
      this.$pt.removeStorageSync('secondPage')
    }
    this.getShopCartVeekray()
  },
  mounted() {
    // 获取胶囊按钮信息
    let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
    // 设备信息
    let devInfo = this.$pt.getSystemInfoSync()
    // 整个导航栏高度
    this.spaceToBarHeight = devInfo['statusBarHeight'] + menuButtonInfo['height'] + (menuButtonInfo['top'] - devInfo['statusBarHeight']) * 2
    this.statusBarHeight = this.$pt.getSystemInfoSync()['statusBarHeight'] + 44
    this.barHeight = this.statusBarHeight - 2
    this.statusBarTop = this.statusBarHeight - 46
    let sysInfo = ''
    sysInfo = this.$pt.getSystemInfoSync()
    this.bScreeSpace = this.statusBarHeight - 61
    this.otherHeight = this.statusBarHeight - 64
    if (sysInfo.system.indexOf('iOS') === -1) {
      this.iosType = true
      // android类型
      this.statusBarTop = this.statusBarHeight - 42
      this.barHeight = this.statusBarHeight - 4
      this.bScreeSpace = this.statusBarHeight - 70
      this.otherHeight = this.statusBarHeight - 75
      if (sysInfo.screenWidth > 375) {
        this.bScreeSpace = this.statusBarHeight - 60
        this.otherHeight = this.statusBarHeight - 65
      }
    }
    if (this.$pt.getSystemInfoSync()['statusBarHeight'] > 35) {
      this.bScreeSpace = this.statusBarHeight - 83
      this.otherHeight = this.statusBarHeight - 88
    }
    if (!Object.keys(this.$pt.getStorageSync('categoryInfo')).length) {
      // 页面初始请求事件
      this.initDataEls()
    }
  },
  methods: {
    getShopCartVeekray() {
      this.effectiveList = []
      this.groupBuyGoodsList = []
      this.listQueryCart.memberId = this.getMemberId
      if (!this.getCustomerId) return
      this.listQueryCart.customerId = this.getCustomerId
      this.listQueryCart.enterpriseId = this.getEnterpriseId || ''
      getShopCartVeekray(this.listQueryCart).then(response => {
        if (response.isError) return
        this.feeGoodsList = []
        this.effectiveList = response.data.effectiveList
        this.groupBuyGoodsList = response.data.groupBuyGoodsList
        this.promotionList = response.data.promotionList
        if (this.promotionList.length) {
          this.promotionList.forEach(item => {
            if (item.feeGoodsList) {
              item.feeGoodsList.forEach(itemSub => {
                this.feeGoodsList.push(itemSub)
              })
            }
          })
        }
        // 设置快速购买缓存数据，以及购物车角标展示
        this.dataFastEls(response.data)
      }).catch(() => {
      })
    },
    dataFastEls(data) {
      this.fastGoods = []
      let storeHomeGoodsList = []
      if (data.storeHomeGoodsList) {
        storeHomeGoodsList = data.storeHomeGoodsList
      }
      let tempAllList = []
      tempAllList = tempAllList.concat(this.effectiveList, this.feeGoodsList, this.groupBuyGoodsList, storeHomeGoodsList)
      if (tempAllList.length) {
        tempAllList.forEach(item => {
          // 重新获取快速购买数据
          if (item.skuId) {
            // 多规格
            let skuData = []
            let objSkuData = {
              skuId: item.skuId,
              goodsNum: item.goodsNum,
              bestPrice: item.bestPrice
            }
            skuData.push(objSkuData)
            let goodsNum = null
            skuData.forEach(item => {
              goodsNum += item.goodsNum
            })
            this.fastGoods.push({
              goodsId: item.goodsId,
              skuFlag: 1,
              skuList: skuData,
              goodsNum: goodsNum
            })
          } else {
            // 单规格
            let objFastGoods = {
              goodsId: item.goodsId,
              skuFlag: 0,
              goodsNum: item.goodsNum,
              bestPrice: item.bestPrice
            }
            this.fastGoods.push(objFastGoods)
          }
        })
      }
      let map = {}
      let dest = []
      this.fastGoods.forEach(item => {
        if (!map[item.goodsId]) {
          if (item.skuFlag) {
            dest.push({
              goodsId: item.goodsId,
              goodsNum: item.goodsNum,
              skuFlag: 1,
              skuList: item.skuList
            })
          } else {
            let objDest = {
              goodsId: item.goodsId,
              goodsNum: item.goodsNum,
              skuFlag: 0,
              bestPrice: item.bestPrice
            }
            dest.push(objDest)
          }
          map[item.goodsId] = item
        } else {
          dest.forEach(itemSub => {
            if (itemSub.goodsId === item.goodsId) {
              itemSub.goodsNum = itemSub.goodsNum + item.goodsNum
              if (item.skuFlag) {
                itemSub.skuList = itemSub.skuList.concat(item.skuList)
              }
            }
          })
        }
      })
      this.fastGoods = []
      this.fastGoods = dest
      this.goodsEls()
      this.resetFastGoodsPrice()
    },
    resetFastGoodsPrice() {
      this.fastGoods.forEach(itemGoods => {
        if (itemGoods.skuFlag) {
          // 多规格
          let totalSellPrice = null
          itemGoods.skuList.forEach(item => {
            totalSellPrice += Math.round((item.goodsNum * item.bestPrice) * 100) / 100
          })
          itemGoods.totalSellPrice = (Math.round(totalSellPrice * 100) / 100).toFixed(2)
        } else {
          // 单规格
          let totalSellPrice = null
          totalSellPrice = (Math.round((itemGoods.goodsNum * itemGoods.bestPrice) * 100) / 100).toFixed(2)
          itemGoods.totalSellPrice = totalSellPrice
        }
      })
    },
    goodsEls() {
      // 快速购买缓存处理
      if (this.getCustomerId && this.getMemberId) {
        if (!this.listData.length) return
        this.listData.forEach(item => {
          if (item.goodsNum) {
            this.onMinusGoodsNum('e', item, '1')
          }
        })
      }
    },
    initDataEls() {
      if (this.getMemberId) {
        this.listData = []
        this.getAuthority()
        // 延迟出现空空如也提示
        setTimeout(() => {
          this.isInitDone = true
        }, 500)
        this.topBoolean = true
        this.current = 0
        this.cartBadge = 1
        this.activeSub = 0
        this.initMemberInfo()
        this.getCategoryNum()
        this.getOpenVipOnlineFlag()
      }
      this.listQuery.currentPage = 1
      this.listQuery.memberId = this.getMemberId
      this.listQuery.customerId = this.getCustomerId
      this.pullLoad.finished = false
    },
    goSearch() {
      if (!this.getShowBuyCard) return
      this.$pt.navigateTo({url: '/pages/shop/searchView/main'})
    },
    getAppEls() {
      getAppInfo().then((response) => {
        if (response.isError) return
        let getAppInfo = response.data
        this.getAppInfo = appColor(getAppInfo)
      }).catch(() => {
      })
    },
    getAuth() {
      this.$pt.login({
        success(res) {
          if (res.code) {
            getAuth(res.code).then((response) => {
              setShowBuyCard(response.data.showBuyCard)
            }).catch(() => {
            })
          }
        }
      })
    },
    // 头像昵称 授权后 立即跳出手机号授权
    authPhoneInfo() {
      this.isGetPhoneInfo = true
    },
    // 授权页 点及返回按钮 重新显示正常页面
    showPage() {
      this.isGetUserInfo = false
      this.isGetPhoneInfo = false
      this.$pt.showTabBar({
        animation: false
      })
    },
    activeClick(index, item) {
      // 切换分类
      // 链接选择器分类跳转进入
      if (this.finishedEls) return
      this.finishedEls = true
      this.leftMenuClick = true
      this.$pt.removeStorageSync('categoryInfo')
      this.finishedLine = false
      this.hasCategory = true
      this.activeIndex = index
      this.listData = []
      this.listQuery.currentPage = 1
      this.activeSub = 0
      if (item.categoryType === 1) {
        this.tempData.templateType = 1
      } else {
        this.tempData.templateType = this.currentTemp
      }
      this.initListCategory()
      // this.getAuthority()
    },
    getHeight(height) {
      // 获取头部导航样式高度 适配手机
      this.spaceHight = height
      // 获取搜索栏高度 适配手机
      const query = this.$pt.createSelectorQuery()
      query.select('.search-bar').boundingClientRect()
      query.selectViewport().scrollOffset()
      query.exec(res => {
        this.seachHeight = res[0].height
        this.leftHight = parseInt(this.spaceHight) + parseInt(this.seachHeight)
        if (this.iosType) {
          this.menuHeight = this.leftHight
        } else {
          this.menuHeight = this.leftHight + 1
        }
      })
    },
    pageTo(item) {
      this.pageLoad = false
      this.$pt.navigateTo({ url: '/pages/shop/detail/main?goodsId=' + item.goodsId + '&goodsType=' + item.goodsType })
    },
    scrollLower() {
      if (!this.pullLoad.finished && !this.finishedEls) {
        this.initGoodsList()
      }
    },
    initListCategory() {
      listOneGoodsCategory({
        memberId: this.getMemberId,
        shopSelectionAuthority: this.shopSelectionAuthority
      }).then((response) => {
        if (response.isError) return
        this.skeletonLoading = false
        this.listCategory = response.data
        // 当前超过数组长度
        if (this.activeIndex > this.listCategory.length - 1) {
          this.activeIndex = 0
        }
        if (this.listCategory.length > 0) {
          this.currentCategory.categoryId = this.listCategory[this.activeIndex].categoryId
          this.currentCategory.categoryType = this.listCategory[this.activeIndex].categoryType
          this.currentCategory.enterpriseCategoryId = this.listCategory[this.activeIndex].enterpriseCategoryId
          this.currentCategory.posterUrl = ''
          if (this.listCategory[this.activeIndex].posterUrl) {
            this.currentCategory.posterUrl = this.listCategory[this.activeIndex].posterUrl
          } else {
            this.currentCategory.posterUrl = null
          }
          this.currentCategory.categoryImage = ''
          if (this.listCategory[this.activeIndex].categoryImage) {
            this.currentCategory.categoryImage = this.listCategory[this.activeIndex].categoryImage
          } else {
            this.currentCategory.categoryImage = null
          }
          if (this.listCategory[this.activeIndex].linkType) {
            this.currentCategory.linkType = this.listCategory[this.activeIndex].linkType
            this.currentCategory.linkParams = this.listCategory[this.activeIndex].linkParams
          } else {
            this.currentCategory.linkType = null
            this.currentCategory.linkParams = null
          }
          // 链接选择器分类跳转进入
          if (this.leftMenuClick) {
            this.categoryId = this.listCategory[this.activeIndex].categoryId
          } else {
            if (this.listCategory.length === 0) return
            this.currentCategory.categoryId = this.categoryId
            let indexOne = this.listCategory.findIndex(listItem => {
              return this.currentCategory.categoryId === listItem.categoryId
            })
            if (indexOne === -1) {
              // categoryInfo 链接选择器分类id，不在分类列表里
              this.activeIndex = 0
              this.currentCategory.categoryId = this.listCategory[0].enterpriseCategoryId
              this.currentCategory.enterpriseCategoryId = this.listCategory[0].enterpriseCategoryId
              this.$pt.removeStorageSync('categoryInfo')
              this.$utils.showToast({ title: '该分类下当前无商品，无法正常显示' })
            } else {
              // categoryInfo 链接选择器分类id，缓存跳转到指定的分类
              // 跳转到1级分类
              this.activeIndex = indexOne
              this.currentCategory.enterpriseCategoryId = this.listCategory[this.activeIndex].enterpriseCategoryId
              this.currentCategory.posterUrl = this.listCategory[this.activeIndex].posterUrl
            }
          }
          this.categoryNull = false
          this.subTab = []
          if (this.tempData.templateType !== 1 && this.currentCategory.enterpriseCategoryId && this.currentCategory.categoryType === 3) {
            this.listNextCategoryByParentId()
            setTimeout(() => {
              this.finishedEls = false
            }, 800)
          } else {
            this.initGoodsList()
          }
          if (this.currentCategory.categoryType === 1 || this.currentCategory.categoryType === 2) {
            this.tempData.templateType = 1
            this.tempData.quickBuy = 1
          }
        } else {
          this.categoryNull = true
        }
      }).catch(() => {
      })
    },
    listNextCategoryByParentId() {
      if (this.tempData.templateType === 3 || this.tempData.templateType === 4) {
        this.shopSortNull = false
      }
      listNextCategoryByParentId({
        enterpriseCategoryId: this.currentCategory.enterpriseCategoryId,
        shopSelectionAuthority: this.shopSelectionAuthority,
        memberId: this.getMemberId
      }).then((response) => {
        if (response.isError) return
        this.subTab = response.data
        if (this.tempData.templateType === 2) {
          this.subTab.unshift({
            enterpriseCategoryId: this.subTab.length ? this.subTab[0].parentId : this.currentCategory.categoryId,
            categoryName: '全部'
          })
        }
        if (this.$pt.getStorageSync('categoryInfo').secondCategoryId) {
          // 如果存在链接跳转至2级分类
          let indexTwo = this.subTab.findIndex(listItem => {
            return this.$pt.getStorageSync('categoryInfo').secondCategoryId === listItem.enterpriseCategoryId
          })
          if (indexTwo === -1) {
            // categoryInfo 链接选择器分类id，不在分类列表里
            this.activeSub = 0
            this.currentCategory.categoryId = this.$pt.getStorageSync('categoryInfo').categoryId
            this.$pt.removeStorageSync('categoryInfo')
            this.$utils.showToast({ title: '该分类下当前无商品，无法正常显示' })
          } else {
            this.activeSub = indexTwo
            this.currentCategory.categoryId = this.$pt.getStorageSync('categoryInfo').secondCategoryId
            this.currentCategory.posterUrl = this.subTab[this.activeSub].posterUrl
          }
        }
        this.initGoodsList()
        if (this.tempData.templateType === 3) {
          let subArrTab = []
          this.subTab.forEach(item => {
            subArrTab.push({
              categoryId: item.categoryId,
              categoryImage: item.categoryImage,
              categoryLevel: item.categoryLevel,
              categoryName: item.categoryName,
              enterpriseCategoryId: item.enterpriseCategoryId,
              enterpriseId: item.enterpriseId,
              parentId: item.parentId,
              showFlag: item.showFlag
            })
          })
          // 手动添加全部分类
          subArrTab.unshift({
            categoryId: this.subTab.length ? this.subTab[0].parentId : this.currentCategory.categoryId, // 取父级的分类分类id
            categoryImage: this.currentCategory.categoryImage ? this.currentCategory.categoryImage : `${this.fileSpace}/images/all-category.png`, // 默认的图片
            // categoryLevel: 2, // 暂定
            categoryName: '全部',
            enterpriseCategoryId: this.subTab.length ? this.subTab[0].parentId : this.currentCategory.categoryId, // enterpriseCategoryId与categoryId一致
            parentId: this.subTab.length ? this.subTab[0].parentId : this.currentCategory.categoryId
          })
          this.subTab = [
            { children: [] }
          ]
          if (this.subTab.length) {
            this.subTab[0].children = subArrTab
          }
          if (this.subTab.length) {
            if (this.subTab[0].children.length === 0) {
              this.shopSortNull = true
            } else {
              this.shopSortNull = false
            }
          }
        }
        if (this.tempData.templateType === 4) {
          // 2级分类没有数据处理开始
          if (!this.subTab.length) {
            this.subTab = [
              { children: [] }
            ]
          }
          // 2级分类没有数据处理结束
          this.subTab.forEach(item => {
            if (!item.children || !item.categoryName) {
              item.children = []
            }
            item.children.unshift({
              categoryId: item.categoryName ? item.enterpriseCategoryId : this.currentCategory.categoryId, // 取父级的分类分类id
              categoryImage: item.categoryImage ? item.categoryImage : `${this.fileSpace}/images/all-category.png`, // 默认的图片
              categoryName: '全部',
              enterpriseCategoryId: item.categoryName ? item.enterpriseCategoryId : this.currentCategory.categoryId, // enterpriseCategoryId与categoryId一致
              parentId: item.categoryName ? item.parentId : this.currentCategory.categoryId
            })
          })
          if (this.subTab.length === 0) {
            this.shopSortNull = true
          } else {
            this.shopSortNull = false
          }
        }
      }).catch(() => {
      })
    },
    initGoodsList() {
      if (this.tempData.templateType === 3 && this.currentCategory.categoryType === 3) return
      if (this.tempData.templateType === 4 && this.currentCategory.categoryType === 3) return
      this.finishedLine = false
      this.shopSortNull = false
      this.listQuery.categoryId = this.currentCategory.categoryId
      this.listQuery.categoryType = this.currentCategory.categoryType
      this.listQuery.shopSelectionAuthority = this.shopSelectionAuthority
      if (this.tempData.templateType === 2 && this.activeSub === 0 && !this.$pt.getStorageSync('categoryInfo')) {
        if (this.subTab.length) {
          this.listQuery.categoryId = this.subTab[0].enterpriseCategoryId
        }
      }
      this.finishedEls = true
      // this.listQuery.categoryType = 3
      pageUserGoodsByMemberId(this.listQuery).then(response => {
        if (response.isError) return
        this.$pt.hideToast()
        response.data.records.forEach(item => {
          // 处理字段长度
          // if (item.goodsStatus === 1 || item.goodsStatus === 0) {
          if (item.goodsStatus === 1) {
            item.shareShow = false
            if (this.getShowBuyCard && item.income && item.income > 0) {
              item.shareShow = true
            }
            const changeData = item.shareShow
            this.$delete(item, 'shareShow')
            this.$set(item, 'shareShow', changeData)
            item.selShow = false
            this.showFastNum(item)
            const selData = item.selShow
            this.$delete(item, 'selShow')
            this.$set(item, 'selShow', selData)
            if (item.totalLimitNum) {
              item.groupLimitNum = item.totalLimitNum
            } else {
              item.groupLimitNum = item.stock
            }
            const limitNumData = item.groupLimitNum
            this.$delete(item, 'groupLimitNum')
            this.$set(item, 'groupLimitNum', limitNumData)
            this.listData.push(item)
          }
        })
        if (!this.listData.length) {
          this.shopSortNull = true
        } else {
          this.shopSortNull = false
        }
        setTimeout(() => {
          this.finishedEls = false
        }, 800)
        // 翻页+1
        if (this.listData.length === 0 || this.listData.length >= response.data.total) {
          this.pullLoad.finished = true
        } else {
          this.listQuery.currentPage++
          this.pullLoad.finished = false
        }
        if (this.pullLoad.finished && this.listData.length > 7) {
          this.finishedLine = true
        }
      }).catch(() => {
      })
    },
    getOpenVipOnlineFlag() {
      getOpenVipOnlineFlag().then((response) => {
        if (response.isError) return
        this.openVip = String(response.data)
      }).catch(() => {
      })
    },
    buyTo() {
      if (this.openVip === '1') {
        this.$pt.navigateTo({ url: '/pages/home/buy/main' })
      }
    },
    // 会员基本信息
    initCustomerInfo() {
      getMemberInfo(this.getCustomerId).then((response) => {
        if (response.isError) return
        this.customerInfo = response.data
        setTimeout(() => {
          if (this.customerInfo.nickname) {
            this.customerInfo.nickname = this.$utils.getStrByLens(this.customerInfo.nickname, 16)
          }
          if (this.customerInfo.memberDetails.personalityName) {
            this.customerInfo.memberDetails.personalityName = this.$utils.getStrByLens(this.customerInfo.memberDetails.personalityName, 30)
          }
          if (!this.getCustomerId) {
            this.customerInfo.avatar = 'https://veekrayimg.joinsun.vip/head-portrait.png'
          }
        }, 500)
      }).catch(() => {
      })
    },
    initMemberInfo() {
      // 如果缓存没有手机号码，则弹出微信授权手机号码
      if (this.getShowBuyCard) {
        if (!this.getCustomerId) {
          // this.$pt.hideTabBar({
          //   animation: false
          // })
        } else {
          this.$pt.showTabBar({
            animation: false
          })
        }
      }
      if (this.getCustomerId) {
        this.initCustomerInfo()
      }
      getMemberInfo(this.getMemberId).then((response) => {
        if (response.isError) return
        this.memberInfo = response.data
        if (response.data.enterpriseId) {
          this.memberEnterpriseId = response.data.enterpriseId || ''
        }
        if (response.data.storeCardFlag) {
          setStoreCardFlag(response.data.storeCardFlag)
        }
        if (response.data.nature) {
          setMemberNature(response.data.nature)
        }
        // 名片模版
        if (this.memberInfo.cardTemp) {
          this.cardTemp = this.memberInfo.cardTemp
        }
        setTimeout(() => {
          if (this.memberInfo.nickname) {
            this.memberInfo.nickname = this.$utils.getStrByLens(this.memberInfo.nickname, 16)
          }
          if (this.memberInfo.memberDetails.personalityName) {
            this.memberInfo.memberDetails.personalityName = this.$utils.getStrByLens(this.memberInfo.memberDetails.personalityName, 30)
          }
        }, 500)
      }).catch(() => {
      })
    },
    tabLayerShow() {
      this.subMore = !this.subMore
    },
    tabClick(e) {
      this.activeSub = e.mp.detail.index
      this.currentCategory.categoryId = this.subTab[this.activeSub].enterpriseCategoryId
      this.listQuery.currentPage = 1
      this.listData = []
      this.initGoodsList()
    },
    subTabLayer(index, item) {
      this.activeSub = index
      this.subMore = false
      this.currentCategory.categoryId = this.subTab[this.activeSub].enterpriseCategoryId
      this.listQuery.currentPage = 1
      this.listData = []
      this.initGoodsList()
    },
    // 运营总后台 增值功能权限获取
    getAuthority() {
      getAuthority({enterpriseId: this.getEnterpriseId ? this.getEnterpriseId : ''}).then(res => {
        this.shopSelectionAuthority = res.data.shopSelectionAuthority
        this.categoryTemplate()
      }).catch(err => {
        console.log(err)
      })
    },
    categoryTemplate() {
      categoryTemplate({
        memberId: this.getMemberId
      }).then((response) => {
        if (response.isError) return
        this.initListCategory()
        this.tempData = response.data
        // this.tempData.templateType = 3
        // this.tempData.quickBuy = 1
        this.currentTemp = response.data.templateType
      }).catch(() => {
      })
    },
    goShopAllPage(item) {
      let params = {
        categoryType: this.currentCategory.categoryType,
        categoryId: item.categoryId,
        enterpriseCategoryId: item.enterpriseCategoryId,
        upperEnterpriseCategoryId: item.parentId
      }
      this.$pt.navigateTo({ url: '/pages/shop/all-goods/main?fromType=1&params=' + JSON.stringify(params) })
    },
    linkTo() {
      let item = {
        linkType: this.currentCategory.linkType,
        linkParams: this.currentCategory.linkParams
      }
      if (item.linkType) {
        const linkType = Number(item.linkType)
        if (item.linkStatus === 0) {
          this.$utils.showToast({title: '链接已失效'})
          return
        }
        if (linkType === 1002) return
        if (linkType === 1004) {
          this.$pt.removeStorageSync('categoryInfo')
          setCategoryInfo(this.$utils.getCaption(item.linkParams))
          this.$pt.switchTab({ url: this.linkList[item.linkType] })
          return
        }
        if (linkType === 1005 || linkType === 1006 || linkType === 1007 || linkType === 1008) {
          this.$pt.switchTab({ url: this.linkList[item.linkType] })
          return
        }
        if (item.linkParams) {
          this.$pt.navigateTo({ url: this.linkList[item.linkType] + item.linkParams })
        } else {
          if (linkType === 1501 || linkType === 1502) {
            this.$pt.navigateTo({ url: this.linkList[item.linkType] + '?enterpriseId=' + this.memberEnterpriseId + '&linkType=' + linkType })
          } else {
            this.$pt.navigateTo({ url: this.linkList[item.linkType] })
          }
        }
      }
    },
    getSkuBuyClose() {
      this.$pt.showTabBar({
        animation: false
      })
    },
    getSkuBuy(isCart, item) {
      if (this.getCustomerId) {
        if (this.shareMemberId) {
          item.shareMemberId = this.shareMemberId
        }
        const comissionFlag = this.getCurrentPage().query.comissionFlag
        this.$refs.getSkuBuy.show(item, isCart, comissionFlag, item.qty)
      } else {
        this.isGetUserInfo = false
        setTimeout(() => {
          this.isGetUserInfo = true
        }, 100)
      }
    },
    getProjectGoodsSku(item) {
      this.goods = this.$utils.deepClone(item)
      this.$utils.showToast({
        title: '加载中',
        icon: 'loading'
      })
      getProjectGoodsSku({
        goodsId: item.goodsId,
        customerId: this.getCustomerId,
        memberId: this.getMemberId,
        microShopFlag: item.goodsType === 30 || item.goodsType === 31 || item.goodsType === 32 ? 0 : 1
      }).then((response) => {
        if (response.isError) return
        this.$pt.hideToast()
        this.goods.skuPropList = response.data.skuPropList
        this.goods.skuList = response.data.skuList
        this.goods.values = response.data.values
        // 社区团购商品，设置featuresType为11
        this.featuresType = ''
        if (item.activityTypeLabel === '团购' || item.activityType === 11) {
          this.featuresType = 11
        }
        this.skuPropList = response.data.skuPropList
        this.skuList = response.data.skuList
        this.values = response.data.values
        this.$pt.hideTabBar({
          animation: false
        })
        setTimeout(() => {
          this.getSkuBuy(true, this.goods)
        }, 100)
      }).catch(() => {
      })
    },
    showCart(item) {
      if (this.getCustomerId) {
        if (this.getPhone) {
          // 自营商品快速购买，添加默认库存
          if (item.goodsType === 10) {
            item.stock = 1000
            const changeStock = item.stock
            this.$delete(item, 'stock')
            this.$set(item, 'stock', changeStock)
          }
          if (item.skuFlag === 1) {
            this.skuPropList = []
            this.skuList = []
            this.values = []
            this.goods = item
            this.goodsType = item.goodsType
            if (item.price) {
              this.goods.price = item.price
            }
            this.goods.images = []
            if (item.mainImage) {
              this.goods.images[0] = item.mainImage
            }
            if (item.firstImage) {
              this.goods.images[0] = item.firstImage
            }
            this.goods.isCart = true
            this.getProjectGoodsSku(item)
          } else {
            item.goodsNum = 1
            this.simpleSkuEls(item)
          }
        } else {
          this.isGetPhoneInfo = true
          this.$pt.hideTabBar({
            animation: false
          })
        }
      } else {
        this.isGetUserInfo = true
        this.$pt.hideTabBar({
          animation: false
        })
      }
    },
    getSkuBuyFinished(params) {
      this.goodsLoad = 0
      this.listData.forEach(item => {
        if (params.goodsId === item.goodsId) {
          let addCount = 0
          if (item.goodsNum) {
            addCount = item.goodsNum + params.goodsNum
          } else {
            addCount = params.goodsNum
          }
          item.goodsNum = addCount
          item.selShow = true
          this.goodsLoad++
          if (this.goodsLoad === 1) {
            this.cartBadgeEls(1, item, params)
          }
        }
      })
    },
    checkGoodsNum(item, type, fastType) {
      let fastGoods = this.fastGoods
      if (fastGoods.length) {
        fastGoods.forEach(itemGoods => {
          if (itemGoods.goodsId === item.goodsId) {
            if (type === 1) {
              item.goodsNum = itemGoods.goodsNum + 1
            } else if (type === -1) {
              if (fastType !== '1') {
                item.goodsNum = itemGoods.goodsNum - 1
              } else {
                item.goodsNum = itemGoods.goodsNum
              }
            } else {
              item.goodsNum = itemGoods.goodsNum
            }
            if (item.goodsNum === 0) {
              item.selShow = false
            }
            const changeData = item.goodsNum
            this.$delete(item, 'goodsNum')
            this.$set(item, 'goodsNum', changeData)
          }
        })
      } else {
        if (type === 1) {
          item.goodsNum = 1
          const changeData = item.goodsNum
          this.$delete(item, 'goodsNum')
          this.$set(item, 'goodsNum', changeData)
        } else if (type === -1) {
          item.goodsNum = 0
          item.selShow = false
          const changeData = item.goodsNum
          this.$delete(item, 'goodsNum')
          this.$set(item, 'goodsNum', changeData)
        }
      }
    },
    onMinusGoodsNum(e, itemOne, fastType) {
      let fastGoods = this.fastGoods
      if (itemOne.skuFlag === 1) {
        let hasGoodsId = this.checkArrInclude(fastGoods, itemOne.goodsId, 'goodsId')
        if (hasGoodsId) {
          this.checkGoodsNum(itemOne, 2, fastType)
        } else {
          itemOne.goodsNum = 0
          itemOne.selShow = false
          const changeData = itemOne.goodsNum
          this.$delete(itemOne, 'goodsNum')
          this.$set(itemOne, 'goodsNum', changeData)
        }
        if (fastType !== '1') {
          this.$utils.showToast({ title: '该商品是多属性商品，请到购物车操作' })
        }
      } else {
        if (itemOne.goodsNum > itemOne.stock) return this.$utils.showToast({ title: '不能大于商品库存' })
        this.goodsLoad = 0
        this.listData.forEach(item => {
          if (itemOne.goodsId === item.goodsId) {
            item.goodsNum = itemOne.goodsNum
            item.selShow = true
            if (!item.goodsNum) {
              item.selShow = false
            }
            this.goodsLoad++
            if (this.goodsLoad === 1) {
              let hasGoodsId = this.checkArrInclude(fastGoods, itemOne.goodsId, 'goodsId')
              if (hasGoodsId) {
                this.checkGoodsNum(itemOne, -1, fastType)
                if (fastType !== '1') {
                  this.addShoppingCart(-1, itemOne)
                }
              } else {
                itemOne.goodsNum = 0
                itemOne.selShow = false
                const changeData = itemOne.goodsNum
                this.$delete(itemOne, 'goodsNum')
                this.$set(itemOne, 'goodsNum', changeData)
              }
              // this.addShoppingCart(-1, itemOne)
            }
          }
        })
      }
    },
    onPlusGoodsNum(e, itemOne) {
      if (itemOne.skuFlag === 1) {
        itemOne.goodsNum = itemOne.goodsNum - 1
        this.skuPropList = []
        this.skuList = []
        this.values = []
        this.goods = itemOne
        this.goodsType = itemOne.goodsType
        this.goods.price = ''
        this.goods.images = []
        this.goods.images[0] = itemOne.mainImage
        this.goods.isCart = true
        this.getProjectGoodsSku(itemOne)
      } else {
        if (itemOne.goodsNum > itemOne.stock) return this.$utils.showToast({ title: '不能大于商品库存' })
        this.simpleSkuEls(itemOne)
      }
    },
    simpleSkuEls(itemOne) {
      this.goodsLoad = 0
      this.listData.forEach(item => {
        if (itemOne.goodsId === item.goodsId) {
          item.goodsNum = itemOne.goodsNum
          item.selShow = true
          this.goodsLoad++
          if (this.goodsLoad === 1) {
            this.addShoppingCart(1, itemOne)
          }
        }
      })
    },
    onChangeGoodsNum(e, item) {
      item.goodsNum = e.mp.detail
    },
    addShoppingCart(value, item) {
      this.addElsShoppingCart(value, item)
    },
    addElsShoppingCart(value, item) {
      if (!this.getShowBuyCard) return
      this.cartBadgeEls(value, item)
      const shoppingCart = {
        customerId: this.getCustomerId,
        goodsId: item.goodsId,
        goodsNum: value,
        memberId: this.getMemberId,
        goodsType: item.goodsType,
        shoppingCartType: item.goodsType === 30 || item.goodsType === 31 || item.goodsType === 32 ? 3 : 1
      }
      addShoppingCart(shoppingCart).then((response) => {
      }).catch(() => {
      })
    },
    // 判断数组是否存在某个key值
    checkArrInclude(arr, item, keyName) {
      let arrData = []
      if (arr.length !== 0) {
        arr.forEach(item => {
          arrData.push(item[keyName])
        })
      }
      if (arrData.includes(item)) {
        return true
      } else {
        return false
      }
    },
    cartBadgeEls(value, item, params) {
      if (!this.$pt.getStorageSync('cartBadge')) {
        this.$pt.removeTabBarBadge({
          index: 2
        })
      }
      // 多规格类型
      if (params !== undefined) {
        // 多规格加、减数量缓存处理
        // console.log(params)
        if (this.fastGoods.length !== 0) {
          // 判段商品是否已经存在
          if (this.checkArrInclude(this.fastGoods, params.goodsId, 'goodsId')) {
            // 已存在goodsId商品
            this.fastGoods.forEach(itemGoods => {
              if (itemGoods.goodsId === params.goodsId) {
                // 已存在skuId商品
                if (this.checkArrInclude(itemGoods.skuList, params.skuId, 'skuId')) {
                  itemGoods.goodsNum = null
                  itemGoods.skuList.forEach(itemSku => {
                    if (itemSku.skuId === params.skuId) {
                      itemSku.goodsNum = itemSku.goodsNum + params.goodsNum
                      itemSku.bestPrice = params.bestPrice
                    }
                    itemGoods.goodsNum += itemSku.goodsNum
                  })
                } else {
                  let objSkuList = {
                    skuId: params.skuId,
                    goodsNum: params.goodsNum,
                    bestPrice: params.bestPrice
                  }
                  itemGoods.skuList.push(objSkuList)
                  itemGoods.goodsNum = null
                  itemGoods.skuList.forEach(itemSku => {
                    itemGoods.goodsNum += itemSku.goodsNum
                  })
                }
              }
            })
          } else {
            // 新增商品
            let skuData = []
            let objSkuData = {
              skuId: params.skuId,
              goodsNum: params.goodsNum,
              bestPrice: params.bestPrice
            }
            skuData.push(objSkuData)
            let goodsNum = null
            skuData.forEach(item => {
              goodsNum += item.goodsNum
            })
            this.fastGoods.push({
              goodsId: params.goodsId,
              skuFlag: 1,
              skuList: skuData,
              goodsNum: goodsNum
            })
          }
        } else {
          let skuData = []
          let objSkuData = {
            skuId: params.skuId,
            goodsNum: params.goodsNum,
            bestPrice: params.bestPrice
          }
          skuData.push(objSkuData)
          let goodsNum = null
          skuData.forEach(item => {
            goodsNum += item.goodsNum
          })
          let objFastGoods = {
            goodsId: params.goodsId,
            skuFlag: 1,
            skuList: skuData,
            goodsNum: goodsNum
          }
          this.fastGoods.push(objFastGoods)
        }
        this.totalCartBadge(params.goodsNum)
        return
      }
      // 单规格类型
      if (value === 1) {
        // 单规格加数量缓存处理
        if (this.fastGoods.length !== 0) {
          // 判段商品是否已经存在
          if (this.checkArrInclude(this.fastGoods, item.goodsId, 'goodsId')) {
            // 已存在商品
            this.fastGoods.forEach(itemGoods => {
              if (itemGoods.goodsId === item.goodsId) {
                itemGoods.goodsNum = item.goodsNum
                itemGoods.bestPrice = item.bestPrice
              }
            })
          } else {
            // 新增商品
            let objData = {
              goodsId: item.goodsId,
              skuFlag: 0,
              goodsNum: item.goodsNum,
              bestPrice: item.bestPrice
            }
            this.fastGoods.push(objData)
          }
        } else {
          let objData = {
            goodsId: item.goodsId,
            skuFlag: 0,
            goodsNum: item.goodsNum,
            bestPrice: item.bestPrice
          }
          this.fastGoods.push(objData)
        }
      } else {
        // 单规格减数量缓存处理
        this.fastGoods.forEach((itemGoods, indexGoods) => {
          if (itemGoods.goodsId === item.goodsId) {
            // 已存在商品
            itemGoods.goodsNum--
            if (!itemGoods.goodsNum) {
              this.fastGoods.splice(indexGoods, 1)
            }
          }
        })
      }
      // console.log('111 this.fastGoods', value, this.fastGoods)
      this.totalCartBadge(value)
      // 清除购物车角标数
      if (!this.fastGoods.length) {
        this.$pt.removeStorageSync('cartBadge')
        this.$pt.removeTabBarBadge({
          index: 2
        })
      }
    },
    cartIndexEls() {
      let cartIndex = null
      this.navList = this.$pt.getStorageSync('navList')
      if (this.navList.length) {
        this.navList.forEach((item, index) => {
          if (item.linkType === 1007) {
            cartIndex = index
          }
        })
      } else {
        cartIndex = 2
      }
      return cartIndex
    },
    totalCartBadge(value) {
      let cartBadge = 0
      if (!this.fastGoods.length) {
        this.$pt.removeStorageSync('cartBadge')
        if (this.cartIndexEls()) {
          this.$pt.removeTabBarBadge({
            index: this.cartIndexEls()
          })
        }
        return
      }
      if (this.cartIndexEls()) {
        this.fastGoods.forEach(itemGoods => {
          cartBadge += itemGoods.goodsNum
        })
        this.$pt.setTabBarBadge({
          index: this.cartIndexEls(),
          text: String(cartBadge)
        })
        setCartBadge(cartBadge)
      }
    },
    showFastNum(item) {
      let cartBadge = 0
      if (!this.fastGoods.length) return
      this.fastGoods.forEach(itemGoods => {
        if (itemGoods.goodsId === item.goodsId) {
          item.selShow = true
          item.goodsNum = itemGoods.goodsNum
        }
      })
      if (this.cartIndexEls()) {
        this.fastGoods.forEach(itemGoods => {
          cartBadge += itemGoods.goodsNum
        })
        this.$pt.setTabBarBadge({
          index: this.cartIndexEls(),
          text: String(cartBadge)
        })
        setCartBadge(cartBadge)
      }
    },
    // 获取分类数量
    getCategoryNum() {
      getCategoryNum(this.getMemberId).then(response => {
        if (response.isError) return
        this.categoryNum = response.data
      })
    },
    confirmShopGuideEdit() {
      this.readShopGuideEdit = true
      this.$pt.setStorageSync('readShopGuideEdit', true)
    },
    goToCart() {
      if (this.getCustomerId) {
        this.$pt.navigateTo({ url: '/pages/shop/cart/main' })
      } else {
        this.isGetUserInfo = false
        setTimeout(() => {
          this.isGetUserInfo = true
        }, 100)
      }
    },
    goToChat() {
      if (!this.getCustomerId) {
        this.isGetUserInfo = false
        setTimeout(() => {
          this.isGetUserInfo = true
        }, 100)
      }
    },
    selCategory(goodsId) {
      this.$refs.upperCategory.selCategory(goodsId, true)
    }
  }
}
</script>

<style lang="less" scoped>
.clear-li{
  padding: 0!important;
  margin: 0!important;
  width: 100%!important;
  font-size: 0;
  clear: both;
}
.tag-goods{
  padding-left: 4px;
  line-height: unset!important;
  font-style: italic;
  font-weight: normal;
  color: #fff;
  font-size: 12px;
  margin-right: 10px;
  box-sizing: border-box;
  display: inline-block;
  width: 37px;
  height: 18px;
  background: url('https://veekrayimg.joinsun.vip/images/shop-tag.png') no-repeat;
  background-size: 100% 100%;
}
.limit-buy-bar{
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  text-align: center;
  padding: 3px 7px;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  font-size: 11px;
  box-sizing: border-box;
  border-radius: 0 0 8px 8px;
}
.top-space{
  height: 64px;
}
.fix-r-btn{
  position: fixed;
  right: 0;
  bottom: 9px;
  z-index: 20;
}
.contactBtn {
  background-color: transparent !important;
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  z-index: 999;
  border-color: transparent !important;
  border: none !important;
}
.skeleton-box{
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1200;
  background-color: #fff;
  overflow: hidden;
  .skeleton-shop{
    border-left: #f5f5f5 90px solid;
  }
  .skeleton-menu{
    border-bottom: #fafafa 1px solid;
  }
  .skeleton-layer{
    margin: 10px;
    &.bg-box{
      border-radius: 5px;
      background-color: #f5f5f5;
    }
    .bg-box{
      border-radius: 5px;
      background-color: #f5f5f5;
    }
    &.layer-1{
      margin-top: 0px;
      height: 54px;
    }
    &.layer-2{        
      span{
        display: block;
        height: 20px;
        &:last-child{
          margin-right: 0!important;
        }
      }
    }
    &.layer-4{
      margin-top: 22px!important;
      .flex-item{
        span{
          display: block;
          border-radius: 5px;
        }
      }
    }
  }
}
.skeleton-layer-bg{
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
  z-index: 79;
}
.over-price{
  text-decoration: line-through;
  color: #999!important;
}
.temp-subcat-list {
  h2 {
    font-size: 15px;
    font-weight: bold;
  }
  ul {
    &:after {
      content: '';
      display: block;
      clear: both;
      font-size: 0;
    }
    li {
      width: 28.3%;
      float: left;
      text-align: center;
      margin: 0 5% 0 0;
      padding-bottom: 8px;
      span {
        display: block;
        background: #e5e5e5;
      }
    }
  }
}
.sub-tab {
  width: calc(100% - 91px);
  overflow: hidden;
  border-bottom: #f6f6f6 1px solid;
  padding-right: 36px;
  box-sizing: border-box;
  position: fixed;
  top: 0px;
  right: 0px;
  z-index: 151;
  .tab-more {
    width: 36px;
    height: 49px;
    position: absolute;
    right: 0;
    top: 0px;
    z-index: 152;
    background: #fff;
    .rotate {
      transform: rotate(180deg);
    }
  }
  /deep/ .van-tabs__line {
    // display: none;
  }
  /deep/ .van-tab.van-tab--active {
    // color: #febf00;
    font-weight: bold;
  }
  /deep/ .van-tab {
    color: #000;
    line-height: 50px;
    padding: 0 !important;
    -webkit-flex: 0 0 29% !important;
    flex: 0 0 29% !important;
  }
  /deep/ .van-tabs--line .van-tabs__wrap {
    height: 50px;
    border-bottom: none !important;
  }
  /deep/ .van-tabs__wrap::after,
  .van-tabs__wrap::before {
    display: none !important;
  }
}
.sub-tab-layer {
  .sub-layer-bg {
    width: calc(100% - 102px);
    height: 100%;
    position: fixed;
    top: 0px;
    right: 0px;
    z-index: 122;
    background: rgba(0, 0, 0, 0.5);
  }
  ul {
    padding-bottom: 4px;
    background: #fff;
    width: calc(100% - 102px);
    position: fixed;
    top: 0px;
    right: 0px;
    z-index: 123;
    &:after {
      content: '';
      display: block;
      clear: both;
      font-size: 0;
    }
    li {
      width: 28%;
      float: left;
      text-align: center;
      color: #666;
      background: #f3f3f3;
      border: #f5f5f5 1px solid;
      margin: 5px 2%;
      padding: 10px 0;
      line-height: 1;
      border-radius: 10em;
      &.actived {
        background: #fffae1;
        color: #febf00;
        border: #ffeb7b 1px solid;
      }
    }
  }
}
.img-top-scr {
  width: 100%;
}
.min-short-w {
  max-width: 70px;
  height: 18px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.container {
  min-height: 100vh;
  background: white;
}
.search-bar {
  padding: 4px 8px 10px 8px;
  width: calc(100% - 16px);
  background: white;
  border-bottom: 1px solid #f3f3f3;
  position: fixed;
  left: 0;
  z-index: 190;
  .search {
    display: flex;
    justify-content: left;
    align-items: center;
    border-radius: 25px;
    height: 30px;
    color: #aeaeae;
    background-color: #f4f4f4;
  }
}
.main {
  .left-bar {
    width: 89px;
    background: #f5f5f5;
    overflow-y: scroll;
    position: fixed;
    left: 0;
    z-index: 1;
    .item-bar {
      height: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 13px;
      color: #666;
      padding: 0 6px;
      overflow: hidden;
      &--active {
        background: white;
        color: #333;
        position: relative;
        font-weight: bold;
        font-size: 14px;
        // &:after {
        //   content: "";
        //   width: 3px;
        //   height: 18px;
        //   background: #ffc808;
        //   position: absolute;
        //   left: 0;
        //   top: 50%;
        //   margin-top: -9px;
        // }
        .leftline {
          position: absolute;
          left: 0;
          top: 50%;
          margin-top: -10px;
          height: 20px;
          width: 4px;
          border-radius: 0 3px 3px 0;
        }
      }
    }
  }
  .right-bar {
    background: white;
    width: calc(100% - 102px);
    padding-left: 12px;
    float: right;
    min-height: 100%;
    position: relative;
    .shop-bar {
      &:last-child {
        .content-item-box {
          border-bottom: unset;
        }
      }
      .img-item-box {
        width: 100px;
        height: 100px;
        .img-item {
          width: 100px;
          height: 100px;
          border-radius: 10px;
        }
        .sell-out {
          position: absolute;
          width: 100px;
          height: 100px;
          left: 0;
          top: 0;
          display: flex;
          justify-content: center;
          align-items: center;
          overflow: hidden;
          color: rgba(254, 254, 254, 0.7);
          background: rgba(0, 0, 0, 0.5);
          font-size: 12px;
          border-radius: 10px;
          .del-layer {
            border-radius: 50%;
            border: 1px solid white;
            justify-content: center;
            width: 60px;
            height: 60px;
          }
          .delete-css {
            position: absolute;
            transform: rotate(-45deg);
            background: rgba(255, 255, 255, 0.58);
            height: 20px;
            line-height: 20px;
            font-size: 12px;
            width: 100%;
            text-align: center;
            color: #000;
          }
        }
      }
      .content-item-box {
        box-sizing: border-box;
        border-bottom: 0.5px solid #f2f2f2;
        .content-title {
          font-size: 14px;
          line-height: 18px;
          color: #333;
        }
        .self-buy {
          height: 15px;
          text-align: center;
          display: flex;
          justify-content: left;
          align-items: center;
          .self-buy-left {
            background: #ffe200;
            font-size: 10px;
            color: #333;
            padding: 0 4px;
          }
          .self-buy-right {
            background: #000000;
            font-size: 10px;
            color: #fff;
            padding: 0 4px;
          }
        }
        .content-foot {          
          .price-row {
            .price-box {
              .price {
                color: #f8303d;
                line-height: 1;
              }
              .old-parice {
                font-size: 12px;
                color: #333;
                text-decoration: line-through;
                margin-left: 5px;
                line-height: 1;
              }
            }
          }
        }
      }
    }
    .nodata {
      padding-top: 50px;
    }
  }
}
.category-nodata {
  padding-top: 180px;
  .goSetting {
    margin-top: 60px;
    button {
      width: 133px;
      height: 33px;
      background: #333333;
      line-height: 33px;
      padding: 0;
      color: white;
      font-size: 15px;
    }
  }
}
.category-nosetting {
  margin-top: 180px;
}
  .top-nav{
    background: #ffffff;
    color: #333;
    overflow: hidden;
    box-sizing: border-box;
    text-align: center;
    font-size: 15px;
    position: fixed;
    width: 100%;
    left: 0;
    top: 0;
    z-index: 100;
    .top-txt{
      font-size: 15px;      
      .txt-min{
        max-width: 90px;
        height: 24px;
        line-height: 1.3;
        overflow:hidden;
        text-overflow:ellipsis;
        display:-webkit-box;
        -webkit-line-clamp:1;
        -webkit-box-orient:vertical;
        word-break:break-word;
      }
    }
    .iconfont{
      margin-top: 3px;
      margin-left: 3px;
      font-size: 15px;
      transform:rotate(90deg);
      &.icon-next{
        margin-top: 0px;
        margin-left: 3px;
        font-size: 15px;
        transform:rotate(0deg);
        color: #292929;
      }
    }
  }
</style>
